package com.mail.server.service;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mail.dubbo.api.SmsHomeBrandApi;
import com.mail.model.db.SmsHomeBrand;
import com.mail.model.vo.PageResult;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SmsHomeBrandService {

    @DubboReference
    private SmsHomeBrandApi smsHomeBrandApi;

    public void addBrand(List<SmsHomeBrand> homeBrandList) {
        for (SmsHomeBrand homeBrand : homeBrandList) {
            smsHomeBrandApi.save(homeBrand);
        }
    }

    public void deleteBrand(List<Long> ids) {
            smsHomeBrandApi.deleteBrand(ids);
    }

    public PageResult getBrandByPage(Long pageNum, Long pageSize, String brandName, Integer recommendStatus) {
        Page<SmsHomeBrand> page =  smsHomeBrandApi.getBrandByPage(pageNum,pageSize,brandName,recommendStatus);
        return new PageResult(Long.parseLong(String.valueOf(page.getCurrent())), Long.parseLong(String.valueOf(page.getSize())), Long.parseLong(String.valueOf(page.getTotal())), page.getRecords());    }

    public void updateBrand(List<Long> ids, Integer recommendStatus) {
        for (Long id : ids) {
            smsHomeBrandApi.updateBrand(id,recommendStatus);
        }
    }

    public void updateSortBrand(Long id, Integer sort) {
        smsHomeBrandApi.updateSortBrand(id,sort);
    }
}
